#!/bin/bash
if test -z "$arch"; then
	arch="i486"
	export arch
fi
VERSION=`date '+%Y%m%d'`
PKG=odcgi
USR="--owner 1000 --group 1000 --same-permissions "
EXCLUDE=" --exclude '*~' --exclude .svn --exclude usr/local/opendomo/services/config/user"

echo "Web interface" > pkg/$PKG.desc
echo "This package allow the access to all the resources in the network" >> pkg/$PKG.desc
cp pkg/*.desc ./var/pkg


make clean && make || exit 1
rm -fr pkg/o*.tar.gz

chmod 0770 usr/local/opendomo/services/syscript/wiz*.sh
chmod 0770 usr/local/opendomo/services/config/*.sh
chmod +x var/pkg/*.sh



if ! test -f var/www/scripts/jquery.flot.js; then
	wget http://www.flotcharts.org/downloads/flot-0.8.1.zip -O flot.zip
	unzip flot.zip
	cp flot/*.js var/www/scripts 
	rm flot/var/www/scripts/jquery.js var/www/scripts/jquery.min.js
fi
JQMFILE="jquery.mobile-1.3.2.zip"
#JQMFILE="jquery.mobile-1.4.0-alpha.2.zip"
if ! test -f $JQMFILE; then
	echo "Downloading jQuery"
	wget -q http://code.jquery.com/jquery-2.0.3.min.js -O var/www/scripts/jquery.min.js
	echo "Downloading jQuery Mobile"
	rm -fr jquery.mobile*.zip jquery-mobile
	wget -q http://jquerymobile.com/resources/download/$JQMFILE  
	mkdir -p jquery-mobile
	unzip jquery.mobile*.zip -d jquery-mobile
	cp -v jquery-mobile/jquery.mobile*min.js var/www/scripts/jquery.mobile.min.js
	cp -v jquery-mobile/jquery.mobile*min.css var/www/css/jquery.mobile.min.css
	cp -v jquery-mobile/images/* var/www/css/images/
	#wget -q http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js -O var/www/scripts/jquery.mobile.min.js
	#wget -q http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css -O var/www/css/jquery.mobile.min.css
fi
#cd jquery
#tar cfz ./../pkg/${PKG}_jquery-$VERSION.noarch.tar.gz var $USR $EXCLUDE
#cd ..
#echo "jQuery library" > pkg/${PKG}_jquery.desc



#cd flot
#chmod 0770 usr/local/opendomo/services/tools/showStats.sh
#tar cfz ./../pkg/${PKG}_flot-$VERSION.noarch.tar.gz var usr $USR $EXCLUDE
#cd ..
#echo "Flot library" > pkg/${PKG}_flot.desc


#cd datepicker
#if ! test -f date-picker-v5/var/www/scripts/datepicker/js/datepicker.packed.js; then
#	tar xvfz date-picker.tar.gz # could not download it from the website, it always fails
#	cp -fR date-picker-v5/* var/www/scripts/datepicker/
#fi

#tar cfz ./../pkg/${PKG}_datepicker-$VERSION.noarch.tar.gz var $USR $EXCLUDE
#cd ..
#echo "Datepicker library" > pkg/${PKG}_datepicker.desc

tar cvfz ./pkg/$PKG-$VERSION.od.$arch.tar.gz var etc usr $USR $EXCLUDE

